Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error for old castep_bin files #296

Merged
merged 4 commits into from
Apr 19, 2024
Merged

Add error for old castep_bin files #296

merged 4 commits into from
Apr 19, 2024

Conversation

mducle
Copy link
Member

@mducle mducle commented Apr 16, 2024

Adds a more helpful error message if users try to use old castep_bin file (pre Castep-17.1).

An alternative fix would involve calculating the supercell_origins field. Some code used in the phonopy reader could possibly be re-used for this.

Fixes #295

@mducle mducle requested a review from ajjackson April 16, 2024 14:18
@mducle mducle added the bug Something isn't working label Apr 16, 2024
Copy link
Contributor

github-actions bot commented Apr 16, 2024

Test Results

0 tests  ±0   0 ✅ ±0   0s ⏱️ ±0s
0 suites ±0   0 💤 ±0 
0 files   ±0   0 ❌ ±0 

Results for commit f48f507. ± Comparison against base commit 2ba0302.

♻️ This comment has been updated with latest results.

@ajjackson
Copy link
Collaborator

The except ValueError makes me a little nervous as this could catch an unrelated error and give the wrong message. Would

cell_origins = _read_entry(f, int_type)
if isinstance(cell_origins, int):
    raise ValueError('Old castep file detected: '
                     'Euphonic only supports post-Castep 17.1 files. '
                     'Please rerun the calculation with a newer version '
                     'of Castep with the original .cell file and a '
                     '.castep file with a single line with the '
                     '"continuation: <old.castep_bin>" keyword and '
                     'use the new output .castep_bin file in Euphonic.')
cell_origins = np.reshape(cell_origins, (n_cells_in_sc, 3))

be a bit safer?

@ajjackson
Copy link
Collaborator

Ok, have pushed that up. It would be helpful to have a small reference file so we can test that the right error is raised. @krefson would you happen to have a very small and old .castep_bin file with force constants we can add to the test set?

The unit test failures seem to be spglib-related, probably there was a breaking API change? I'll take a look.

@mducle
Copy link
Member Author

mducle commented Apr 18, 2024

Thanks Adam! I was going to try to look into the test failure - it doesn't seem to be related to this (I get the same errors on master) - but I guess that should probably go into a different PR...

@krefson
Copy link

krefson commented Apr 18, 2024

The dump files contain a version number, and I suggest checking against that.

The checkpoint version is encoded as a floating-point number as ASCII in a character*10 field in the record immediately following BEGIN_PARAMETERS_DUMP.

The format change was introduced in CASTEP 17.x, so testing for < 17.0 and reporting "not supported" should work as a robust safeguard.

@krefson
Copy link

krefson commented Apr 18, 2024

If you really wanted to read dump files with version <= 16.x, then you will indeed need to recompute the supercell_origins vector. There is a short Fortran routine cell.f90 named cell_generate_supercell_origins which would be easy to transliterate into Python.

@ajjackson
Copy link
Collaborator

I don't think we need to support CASTEP versions < 17, especially if an external workaround is available.

I'll implement the version number check, that seems a better way of handling things.

@ajjackson
Copy link
Collaborator

Ok, I am using packaging.version to compare the version numbers. This adds a dependency, unfortunately, but

  • it is quite a common one that replaces some things that were in standard library
  • (e.g. it is also required by matplotlib, sphinx, black and ipython)
  • it makes a rather ugly comparison operation very clean and easy 😅

@ajjackson
Copy link
Collaborator

I think we should wait until #298 is merged and rebase this branch in order to get a clean error check before a final review/merge.

mducle and others added 3 commits April 18, 2024 16:11
"except ValueError" is a bit broad and could catch unrelated
problems. Checking that _read_entry returned an int is still not 100%
specific to the problem but seems safer.
Copy link
Member Author

@mducle mducle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for making the check much better!

In the interest of keeping a clean commit history maybe we ought to actually close this PR unmerged and create a new one with just the last commit (checking the Castep version in the .castep_bin file)?

@ajjackson
Copy link
Collaborator

We can also achieve that from this PR with the "squash and merge" option. I'll add a changelog line first, though.

@ajjackson ajjackson merged commit be51d81 into master Apr 19, 2024
10 checks passed
@mducle mducle deleted the castep16_warning branch April 19, 2024 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot read Castep 16.11 bin file
3 participants